package org.facyt.vacas.entities.vacas.restricciones;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.facyt.vacas.entities.vacas.Alimento;
import org.facyt.vacas.entities.vacas.Componente;


@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name="restriccion", schema="vacas")
public abstract class Restriccion implements Serializable, RestriccionI {

	@Id
	@SequenceGenerator(name="restriccion_seq", sequenceName="vacas.restriccion_id_seq")
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="restriccion_seq")
	@Column(name="id")
	protected Integer id;
	
	@Column(name="esf")
	private Boolean esF; 
	
	@Column(name="esr")
	protected boolean esR;
	
	@Column(name="esModificable")
	protected boolean esModificable;
	
	@Column(name="modificada")
	protected boolean modificada;
	
	@Column(name="calculo")
	protected Integer calculo;
	
	@ManyToOne
	@JoinColumn(name = "fk_componente")
	protected Componente componente;
	
	@ManyToOne (cascade=CascadeType.ALL)
	@JoinColumn(name = "fk_alimento")
	private Alimento alimento;


	public Alimento getAlimento() {
		return alimento;
	}
	public void setAlimento(Alimento alimento) {
		this.alimento = alimento;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public boolean isEsF() {
		return esF;
	}
	
	/*
	 @Transient
    public boolean getIsActive() {
        return isActive;
    }
    public void setIsActive(boolean isActive) {
        this.isActive = isActive;
    }
    @Basic
    private String getIsActiveValue() {
        if (isActive) {
            return "T";
        } else {
            return "F";
        }
    }
    private void setIsActiveValue(String isActive) {
        this.isActive = "T".equals(isActive);
    }
	 **/
	public void setEsF(boolean esF) {
		this.esF = esF;
	}
	public boolean isEsR() {
		return esR;
	}
	public void setEsR(boolean esR) {
		this.esR = esR;
	}
	public boolean isEsModificable() {
		return esModificable;
	}
	public void setEsModificable(boolean esModificable) {
		this.esModificable = esModificable;
	}
	public boolean isModificada() {
		return modificada;
	}
	public void setModificada(boolean modificada) {
		this.modificada = modificada;
	}
	public Integer getCalculo() {
		return calculo;
	}
	public void setCalculo(Integer calculo) {
		this.calculo = calculo;
	}
	public Componente getComponente() {
		return componente;
	}
	public void setComponente(Componente componente) {
		this.componente = componente;
	}
	/***********************metodos anteriuores*******************************/
	
		//si esF es true; entonces no es R(recuento) sino que la restriccion se usa para formulacion

	public String getComparacionConFormulacion(BigDecimal cantXKilo)
	{
//		System.out.println("getComparacionConFormulacion cambiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrr acacca");
		
	    return "";
	}
    /**
     * @param f
     * @return
     */
    public String getComparacion(BigDecimal f) {      
        return "";
    }
		
	public String getRFoNada()
	{
		if(esR)
			return "R";
		else
			if(esF)
				return "F";
			else
				return " - ";
	}
	
/*	private void setearEsREsF(String valor)
	{
		if(valor.equalsIgnoreCase("R"))
		{
			setEsR(true);
			setEsF(false);
		}else
		{
			if(valor.equalsIgnoreCase("F"))
			{
				setEsR(false);
				setEsF(true);
			}
			else
			{
				setEsR(false);
				setEsF(false);
			}
				
		}
	}
	
	public void setearEsREsF()
	{
		setEsR(this.isEsR());
		setEsF(this.isEsF());			
	}
*/	
	public void setearEsR()
	{
		setEsR(true);
		setEsF(false);
		
	}

	public void setearEsF()
	{
		setEsR(false);
		setEsF(true);		
	}
	public String getRestriccionToString() {
//		System.out.println("getRestriccionToString cambiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrr acacca");
		
		return null;
		
	}
	public Object clone() throws CloneNotSupportedException {
//		System.out.println("cloneeeeee   cambiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrr acacca");
		return null;
	}
	public BigDecimal getCalculoInversoRestriccion(BigDecimal valor, BigDecimal energia, 
			  Alimento alimento, boolean esMinimo) {
//		System.out.println("getCalculoInversoRestriccion cambiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrr acacca");
		return new BigDecimal("0");
	}
	
	public void guardarFInverso(BigDecimal valor, BigDecimal energia, 
			Alimento alimento, boolean esMinimo) {
		
	}
	public String getToString() {
		System.out.println("getToString  cambiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrr acacca");
		return "";
	}
	
	public String getStringRestriccion()
	{
		return getRestriccionToString()+" "+ getToString();
	}
	public String toStringFormulacionRestriccion() {
		// TODO Auto-generated method stub
		return "";
	}


}
